#include <iostream>
#include <list>
#include <string>
using namespace std;

template <class T>
void output(T s,T e){
	for( ;s!=e; ++s ){
		cout<<*s<<" ";
	}
	cout<<endl;
}
int main(){
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	int n,a,b;
	string op;
	list<int> lst[10000];
	cin>>n;
	while( n--){
		cin>>op>>a;
		switch (op[0]){
			case 'n':break;
			case 'a': cin>>b; lst[a].push_back(b); break;
			case 'm':cin>>b;lst[a].merge(lst[b]);break;
			case 'u':lst[a].sort(); lst[a].unique();break;
			case 'o':lst[a].sort();output(lst[a].begin(),lst[a].end());break;
		}
	}
}
